package cn.jinjimi.app.main.adapter.pagerAdapter;

import android.content.Context;
import android.graphics.PointF;
import android.view.View;
import android.view.ViewGroup;

import com.facebook.drawee.drawable.ScalingUtils;
import com.facebook.imagepipeline.request.Postprocessor;

import cn.jinjimi.app.entity.LinkBean;
import cn.jinjimi.base.util.URLUtil;
import cn.jinjimi.app.R;
import cn.jinjimi.app.bean.EventID;
import cn.jinjimi.app.entity.Advertisement;
import cn.jinjimi.app.main.widget.FrescoImageView.FrescoImageView;

import java.util.List;

/**
 * 广告图片数据适配器
 * @author zhenhua
 */
public class AdvAdapter extends CyclePagerAdapter<LinkBean> {

    private Context mContext;
    private View.OnClickListener mClickListener;
    private int resId;
    private Postprocessor mProcessor;

    public void setClickListener(View.OnClickListener clickListener) {
        mClickListener = clickListener;
    }

    public void setProcessor(Postprocessor mProcessor) {
        this.mProcessor = mProcessor;
    }

    public AdvAdapter(Context context) {
        this(context, R.drawable.default_bg);
    }

    public AdvAdapter(Context context, int resId) {
        mContext = context;
        this.resId = resId;
    }

    @Override
    public View getView(ViewGroup container, int position) {
        final LinkBean advertisement = getItem(position);
        if (advertisement != null) {
            FrescoImageView view = new FrescoImageView(mContext);
            view.setActualImageScaleType(ScalingUtils.ScaleType.FOCUS_CROP);
            view.getHierarchy().setActualImageFocusPoint(new PointF(0.5f, 1f));
            if (mProcessor != null) {
                view.setPostProcessor(mProcessor);
            }
            view.setTag(R.id.url, advertisement.link);
            view.setTag(position);
            //bind tap event
            if (null != mClickListener)
                view.setOnClickListener(mClickListener);

            //获取图片列表
            view.loadView(advertisement.img, resId);
            return view;
        }
        return null;
    }
}
